package common;

import java.awt.*;

import client.Canvas;


public class Player
{
	public static final int PLAYER1 = 0;
	public static final int PLAYER2 = 1;
	public static final int PLAYER3 = 2;
	public static final Color[] PLAYERCOLOR = {Color.CYAN,Color.YELLOW,Color.GREEN};
	public static enum Status{ ALIVE, DEAD};

	private final int RADIUS = 15;
	private final int FIELDOFFSET = Canvas.FIELDSIZE/2 - RADIUS;
	
	private int posX;
	private int posY;
	private Color color;
	private int score;
	private Status status; 
	
	public Player( int posX, int posY, Color color){
		this.posX = posX;
		this.posY = posY;
		this.color = color;
		this.score = 0;
		this.status = Status.ALIVE;
	}
	
	public void draw( Graphics g ){
		g.setColor( color );
		g.fillOval( Canvas.OFFSET + FIELDOFFSET + Canvas.FIELDSIZE*posX,
					Canvas.OFFSET + FIELDOFFSET + Canvas.FIELDSIZE*posY,
					RADIUS*2,
					RADIUS*2 );
		
		g.setColor( Color.BLACK );
		g.drawOval( Canvas.OFFSET + FIELDOFFSET + Canvas.FIELDSIZE*posX,
				Canvas.OFFSET + FIELDOFFSET + Canvas.FIELDSIZE*posY,
				RADIUS*2,
				RADIUS*2 );
	}

	public void moveUp( Level level){
		if( posY > 0 && !level.getField( posY-1, posX).equals( "X")){
			posY--;
		}
	}
	public void moveDown( Level level){
		if( posY < level.getRowAmount()-1 && !level.getField( posY+1, posX).equals( "X")){
			posY++;
		}
	}
	public void moveRight( Level level){
		if( posX < level.getColumnAmount()-1 && !level.getField( posY, posX+1).equals( "X")){
			posX++;
		}
	}
	public void moveLeft( Level level){
		if( posX > 0 && !level.getField( posY, posX-1).equals( "X")){
			posX--;
		}
	}
	
	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}
}
